<template>
<label v-if="!labelHidden"
       :style="field.labelStyle"
       :class="[schema.commonLabelClass, field.labelClass]">{{label}}</label>
</template>

<script>
import _ from 'lodash'

export default {
  props: {
    schema: {
      type: Object,
      default () {
        return {}
      }
    },
    field: {
      type: Object,
      default () {
        return {}
      }
    },
    model: {
      type: Object,
      default () {
        return {}
      }
    },
    formModel: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  computed: {
    label () {
      if (_.isNil(this.field.label)) {
        return this.field.name
      }
      return this.field.label
    },
    labelHidden () {
      if (_.isNil(this.field.labelHidden)) {
        return false
      }
      if (_.isFunction(this.field.labelHidden)) {
        return this.field.labelHidden(this.model, this.formModel, this.field)
      }
      return !!this.field.labelHidden
    }
  }
}
</script>
